var qiniu = require('qiniu');
var accessKey = 'k6KUdarbJ6QDrv6_o6hHIVb2IA-OXhDMrgAi6jBn';
var secretKey = 'gbN4U0d5-rdec7mGK-y0IkZZLgYajh6cejvuO-tP';
var mac = new qiniu.auth.digest.Mac(accessKey, secretKey);
var options = {
    scope: 'zjl606-web', // bucket
    expires: 7200
};
var putPolicy = new qiniu.rs.PutPolicy(options);
var uploadToken=putPolicy.uploadToken(mac);
console.log('uploadToken::::--', uploadToken);

var config = new qiniu.conf.Config();
// 空间对应的机房
config.zone = qiniu.zone.Zone_z0;
// var localFile = "/Users/qsym/Desktop/gui.jpg";
var formUploader = new qiniu.form_up.FormUploader(config);
var putExtra = new qiniu.form_up.PutExtra();
var key='gui.jpg';


function updateImg(localFile, callback) {
  // 文件上传
  formUploader.putFile(uploadToken, key, localFile, putExtra, function(respErr,
    respBody, respInfo) {
    if (respErr) {
      throw respErr;
    }
    if (respInfo.statusCode == 200) {
      console.log(respBody);
      callback(respBody);
    } else {
      console.log(respInfo.statusCode);
      console.log(respBody);
    }
  });
}

// updateImg(localFile, function(res) {
//   console.log('res---', res);
// })

module.exports = updateImg;